<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/pages/template.xhtml">
	<ui:define name="corpo">
		<h:form id="justificativaForm">
			<h:inputHidden
				value="#{justificativaBean.justificativa.justificativaId}" />
			<p:growl id="growl" life="2500"></p:growl>
			<p:ajaxStatus onstart="statusDialog.show();"
				onsuccess="statusDialog.hide();" />

			<p:dialog modal="true" widgetVar="statusDialog" header="Carregando"
				draggable="false" closable="false">
				<p:graphicImage value="/resources/imagens/ajax-loader-bar.gif"></p:graphicImage>
			</p:dialog>
			<p:panel id="panel" header="#{justificativaBean.labelCadastro}">
				<p:panelGrid style="margin-top:10px;width:99%">
					<p:row>
						<p:column colspan="2" style="text-align:left">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.solicitante']}#{msgs['form.label.doispontos']} " />
							<h:outputText id="solicitante"
								value="#{justificativaBean.justificativa.solicitante.nome}"
								style="text-align:left" />
						</p:column>
						<p:column colspan="2" style="text-align:right">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.datacriacao']}#{msgs['form.label.doispontos']} " />
							<h:outputText
								value="#{justificativaBean.justificativa.dtCriacao}">
								<f:convertDateTime pattern="#{msgs['sistema.formato.data']}" />
							</h:outputText>
						</p:column>
					</p:row>
					<p:row>
						<p:column colspan="3" styleClass="ui-widget-header">
							<p:spacer height="0" />
						</p:column>
					</p:row>
					<p:row>
						<p:column colspan="3" style="text-align:right">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.situacao']}#{msgs['form.label.doispontos']} " />
							<h:outputText value="#{justificativaBean.justificativa.status}">
								<f:converter converterId="StatusConverter" />
							</h:outputText>
						</p:column>
					</p:row>
				</p:panelGrid>

				<p:separator styleClass="tabela" />

				<p:panelGrid id="pgrdDetalhamento" styleClass="tabela">
					<p:row>
						<p:column style="text-align:left; width:110px;">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.motivo']}#{msgs['form.label.doispontos']} " />
						</p:column>
						<p:column colspan="3">
							<p:selectOneMenu id="motivo"
								disabled="#{!justificativaBean.acesso.editaSolicitante}"
								value="#{justificativaBean.justificativa.motivo}"
								valueChangeListener="#{justificativaBean.handler.mudouMotivo}"
								required="true"
								requiredMessage="#{msgs['form.justificativa.motivo.required']}">
								<p:ajax event="change" update="pgrdDetalhamento" />
								<f:selectItem itemValue="" itemLabel="" />
								<f:selectItems
									value="#{justificativaBean.handler.tipoMotivosList}" />
							</p:selectOneMenu>
							<p:message id="motivoMsg" for="motivo" />
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align:left; width:110px;">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.horario']}#{msgs['form.label.doispontos']} "
								rendered="#{justificativaBean.handler.configuracao['HORA_INI']}" />
						</p:column>
						<p:column>
							<p:calendar styleClass="calendar"
								disabled="#{!justificativaBean.acesso.editaSolicitante}"
								value="#{justificativaBean.justificativa.hrIni}" id="hrini"
								showOn="button" pattern="#{msgs['sistema.formato.hora']}" timeOnly="true" required="true"
								requiredMessage="#{msgs['form.justificativa.hrini.required']}"
								rendered="#{justificativaBean.handler.configuracao['HORA_INI']}" />
							<p:message id="hriniMsg" for="hrini" />
						</p:column>
						<p:column style="text-align:right">
							<h:outputLabel value=" #{msgs['form.justificativa.label.ate']} "
								rendered="#{justificativaBean.handler.configuracao['HORA_FIM']}" />
						</p:column>
						<p:column>
							<p:calendar styleClass="calendar"
								disabled="#{!justificativaBean.acesso.editaSolicitante}"
								value="#{justificativaBean.justificativa.hrFim}" id="hrfim"
								showOn="button" pattern="#{msgs['sistema.formato.hora']}" timeOnly="true" required="true"
								requiredMessage="#{msgs['form.justificativa.hrfim.required']}"
								rendered="#{justificativaBean.handler.configuracao['HORA_FIM']}" />
							<p:message id="hrfimMsg" for="hrfim" />
						</p:column>
					</p:row>
					<p:row
						rendered="#{justificativaBean.handler.configuracao['CAUSA_FALTA']}">
						<p:column style="text-align:left; width:110px;">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.causafalta']}#{msgs['form.label.doispontos']} "
								id="lbCausaFalta" />
						</p:column>
						<p:column colspan="3">
							<p:selectOneMenu id="causafalta" required="true"
								disabled="#{!justificativaBean.acesso.editaSolicitante}"
								requiredMessage="#{msgs['form.justificativa.erro.causafalta']}"
								value="#{justificativaBean.justificativa.tipofalta}">
								<f:selectItem itemValue="" itemLabel="" />
								<f:selectItems
									value="#{justificativaBean.handler.tipoFaltaList}" />
							</p:selectOneMenu>
							<p:message id="causafaltaMsg" for="causafalta" />
						</p:column>
					</p:row>
					<p:row
						rendered="#{justificativaBean.handler.configuracao['TIPO_BANCO_HORAS']}">
						<p:column style="text-align:left; width:110px;">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.bancohoras']}#{msgs['form.label.doispontos']} " />
						</p:column>
						<p:column colspan="3">
							<p:selectOneMenu id="tipobancohoras"
								disabled="#{!justificativaBean.acesso.editaSolicitante}"
								value="#{justificativaBean.justificativa.tipobancohoras}"
								required="true"
								requiredMessage="#{msgs['form.justificativa.tipobancohoras.required']}">
								<f:selectItem itemValue="" itemLabel="" />
								<f:selectItems value="#{justificativaBean.tipoBancoHorasList}" />
							</p:selectOneMenu>
							<p:message id="tipobancohorasMsg" for="tipobancohoras" />
						</p:column>
					</p:row>
				</p:panelGrid>

				<p:fieldset
					legend="#{msgs['form.justificativa.legenda.justificativa']}"
					id="justificativaGrid">
					<p:row>
						<p:column style="text-align:left">
							<p:inputTextarea id="descricao" rows="5" cols="30"
								disabled="#{!justificativaBean.acesso.editaSolicitante}"
								maxlength="300" autoResize="true" required="true"
								requiredMessage="#{msgs['form.justificativa.justificativa.required']}"
								value="#{justificativaBean.justificativa.descricao}" />
							<p:message id="descricaoMsg" for="descricao" />
						</p:column>
					</p:row>
				</p:fieldset>

				<p:panelGrid id="coordenadorGrid" styleClass="tabela">
					<p:row>
						<p:column style="table-layout:fixed;width:130px">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.coordenador']}#{msgs['form.label.doispontos']} " />
						</p:column>
						<p:column>
							<p:selectOneMenu id="coordenadorSelect"
								value="#{justificativaBean.idCoordenador}" required="true"
								disabled="#{not justificativaBean.acesso.editaSolicitante}"
								requiredMessage="#{msgs['form.justificativa.coordenador.required']}">
								<f:selectItem itemValue="" itemLabel="" />
								<f:selectItems value="#{justificativaBean.coordenadorList}" />
							</p:selectOneMenu>
							<p:message id="coordenadorSelectMsg" for="coordenadorSelect" />
						</p:column>
					</p:row>
				</p:panelGrid>


				<p:panelGrid id="superintendenteGrid" styleClass="tabela">
					<p:row>
						<p:column style="table-layout:fixed;width:130px">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.superintendente']}#{msgs['form.label.doispontos']} " />
						</p:column>
						<p:column>
							<p:selectOneMenu id="superintendenteSelect"
								value="#{justificativaBean.idSuperintendente}" required="true"
								disabled="#{not justificativaBean.acesso.editaCoordenador}"
								requiredMessage="#{msgs['form.justificativa.superintendente.required']}">
								<f:selectItem itemValue="" itemLabel="" />
								<f:selectItems value="#{justificativaBean.superintendenteList}" />
							</p:selectOneMenu>
							<p:message id="superintendenteSelectMsg"
								for="superintendenteSelect" />
						</p:column>
					</p:row>
				</p:panelGrid>

				<p:panelGrid id="rhUserId" styleClass="tabela">
					<p:row>
						<p:column style="table-layout:fixed;width:130px">
							<h:outputLabel
								value="#{msgs['form.justificativa.label.rh']}#{msgs['form.label.doispontos']} " />
						</p:column>
						<p:column>
							<p:selectOneMenu id="rhSelect" value="#{justificativaBean.idRh}"
								disabled="#{not justificativaBean.acesso.editaSuperintendente}"
								required="true"
								requiredMessage="#{msgs['form.justificativa.rh.required']}">
								<f:selectItem itemValue="" itemLabel="" />
								<f:selectItems value="#{justificativaBean.rhList}" />
							</p:selectOneMenu>
							<p:message id="rhSelectMsg" for="rhSelect" />
						</p:column>
					</p:row>
				</p:panelGrid>

				<p:fieldset
					legend="#{msgs['form.justificativa.legenda.instrucoesrh']}"
					id="rhGrid">
					<p:panelGrid styleClass="semBorda">
						<p:row>
							<p:column>
								<h:outputLabel
									value="#{msgs['form.justificativa.label.tipoDecisao']}#{msgs['form.label.doispontos']} " />
								<p:selectOneMenu id="decisaoRh"
									disabled="#{not justificativaBean.acesso.editaRh}"
									value="#{justificativaBean.justificativa.tipoDecisao}"
									required="true"
									requiredMessage="#{msgs['form.justificativa.decisaorh.required']}">
									<f:selectItem itemValue="" itemLabel="" />
									<f:selectItems value="#{justificativaBean.tipoDecisaoList}" />
								</p:selectOneMenu>
								<p:message id="decisaoRhMsg" for="decisaoRh" />
							</p:column>
						</p:row>
						<p:row>
							<p:column style="text-align:left">
								<h:outputLabel
									value="#{msgs['form.justificativa.label.observacao']}#{msgs['form.label.doispontos']} " />
								<p:inputTextarea id="obsRh" rows="5" cols="30"
									disabled="#{not justificativaBean.acesso.editaRh}"
									maxlength="300" autoResize="true" required="true"
									requiredMessage="#{msgs['form.justificativa.observacao.required']}"
									value="#{justificativaBean.justificativa.obsRh}" />
								<p:message id="obsRhMsg" for="obsRh" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:fieldset>

				<!-- AUTOR SOLICITANTE -->
				<p:commandButton id="enviarCoord"
					rendered="#{justificativaBean.acesso.editaSolicitante}"
					value="#{msgs['form.justificativa.botao.enviarcoord']}"
					update="growl panel"
					action="#{justificativaBean.enviarCoordenador}"
					icon="ui-icon-circle-arrow-e" ajax="false" />

				<!-- AUTOR COORDENADOR -->
				<p:commandButton id="enviarSuperintendente"
					rendered="#{justificativaBean.acesso.editaCoordenador}"
					value="#{msgs['form.justificativa.botao.enviarsuperintendente']}"
					update="growl panel"
					action="#{justificativaBean.enviarSuperintendente}"
					icon="ui-icon-circle-arrow-e" ajax="false">
					<f:param value="#{justificativaBean.justificativa.justificativaId}"
						name="id" />
				</p:commandButton>

				<!-- AUTOR SUPERINTENDENTE -->
				<p:commandButton id="executarRH"
					rendered="#{justificativaBean.acesso.editaSuperintendente}"
					value="#{msgs['form.justificativa.botao.enviarexecucaorh']}"
					update="growl panel" action="#{justificativaBean.enviarRh}"
					icon="ui-icon-circle-arrow-e" ajax="false">
					<f:param value="#{justificativaBean.justificativa.justificativaId}"
						name="id" />
				</p:commandButton>

				<!-- AUTOR RH -->
				<p:commandButton id="btnConcluidoRH"
					rendered="#{justificativaBean.acesso.editaRh}"
					value="#{msgs['form.justificativa.botao.concluidorh']}"
					update="growl panel" action="#{justificativaBean.concluiRh}"
					icon="ui-icon-circle-arrow-e" ajax="false">
					<f:param value="#{justificativaBean.justificativa.justificativaId}"
						name="id" />
				</p:commandButton>

				<!-- AUTORES: COORDENADOR;SUPERINTENDENTE;RH;ADMIN -->
				<p:commandButton id="btnCancelar"
					rendered="#{justificativaBean.acesso.cancelar}"
					value="#{msgs['form.justificativa.botao.cancelar']}"
					oncomplete="cadDialog.show()" icon="ui-icon-circle-arrow-e">
					<f:param name="id"
						value="#{justificativaBean.justificativa.justificativaId}" />
				</p:commandButton>
			</p:panel>


			<p:separator style="margin-top: 20px;" />

			<p:panel header="#{msgs['form.justificativa.legenda.historico']}"
				style="margin-top: 20px;">

				<p:dataTable var="historico"
					value="#{justificativaBean.justificativa.historicoOrdenado}"
					id="tblHistoricoJustificativa">
					<p:column id="colDataHistorico">
						<f:facet name="header">
							<h:outputText
								value="#{msgs['form.justificativa.tabela.historico.coluna.data']}" />
						</f:facet>
						<h:outputText value="#{historico.data}">
							<f:convertDateTime pattern="#{msgs['sistema.formato.data']}" />
						</h:outputText>
					</p:column>
					<p:column id="colUsuarioHistorico">
						<f:facet name="header">
							<h:outputText
								value="#{msgs['form.justificativa.tabela.historico.coluna.usuario']}" />
						</f:facet>
						<h:outputText value="#{historico.usuario.nome}" />
					</p:column>
					<p:column id="colEventoHistorico">
						<f:facet name="header">
							<h:outputText
								value="#{msgs['form.justificativa.tabela.historico.coluna.evento']}" />
						</f:facet>
						<h:outputText value="#{msgs[historico.tipoEvento.descricao]}" />
					</p:column>
				</p:dataTable>
			</p:panel>
		</h:form>

		<p:ajaxStatus onstart="statusDialog.show();"
			onsuccess="statusDialog.hide()" />

		<p:dialog modal="true" widgetVar="statusDialog" header="Status"
			draggable="false" closable="false" resizable="false">
			<p:graphicImage value="/resources/imagens/ajax-loader-bar.gif" />
		</p:dialog>


		<p:dialog id="idDialogCancel" widgetVar="cadDialog"
			header="#{msgs['dialog.cancelar.titulo']}" closable="true"
			resizable="false" modal="true" hideEffect="slide" showEffect="slide"
			draggable="false">

			<h:form id="formCancelaId">
				<h:panelGrid id="display" cellpadding="4" style="margin:0 auto;">
					<p:messages />
					<p:separator />
					<p:inputTextarea id="motivoCancela" rows="5" cols="30"
						maxlength="300" autoResize="true"
						requiredMessage="#{msgs['dialog.cancelar.valida.justificativa']}"
						required="true"
						value="#{justificativaBean.justificativa.cancelamento}" />
					<p:column colspan="2">
						<p:commandButton id="btsalvar"
							value="#{msgs['dialog.cancelar.botao.salvar']}" update="display"
							actionListener="#{justificativaBean.cancelado}"
							oncomplete="handleCancelRequest(xhr, status, args)">
							<f:param name="id"
								value="#{justificativaBean.justificativa.justificativaId}" />
						</p:commandButton>
						<p:commandButton value="Voltar" update="display" process="@this"
							oncomplete="cadDialog.hide()">
						</p:commandButton>
					</p:column>
				</h:panelGrid>
			</h:form>
		</p:dialog>
		<script type="text/javascript">
			function handleCancelRequest(xhr, status, args) {
				if (args.validationFailed || !args.cancelado) {
					jQuery('#idDialogCancel').effect("shake", {
						times : 3
					}, 100);
				} else {
					cadDialog.hide();
					location.href = 'welcome.jsf';
				}
			}
		</script>
	</ui:define>
</ui:composition>